package com.hdu.hot100.list;


import java.util.List;

public class lc206 {

    public class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    class Solution {
        public ListNode reverseList(ListNode head) {
            return method2(head);
        }


        ListNode method1(ListNode head)
        {
            if (head == null || head.next == null) return head;
            ListNode cur = method1(head.next);
            head.next.next = head;
            head.next = null;
            return cur;
        }

        ListNode method2(ListNode head)
        {
            ListNode prev = null;
            ListNode cur = head;
            while (cur != null)
            {
                ListNode next = cur.next;
                cur.next = prev;
                prev = cur;
                cur = next;
            }
            return prev;
        }
    }
}
